// @ts-check
import { createServer, logger } from 'f2e-server3'
import * as path from 'path'

const basePath = path.join(process.cwd(), './__sources__')

createServer({
    mode: "prod",
    port: 2850,
    try_files: 'index.html',
    proxies: [
        {
            location: /^\/?(\$[^/]+)/,
            origin: (url) => `https://${url.match(/^\/?\$([^/]+)/)?.[1]}`,
            pathname: '',
            requestOptions: {
                rejectUnauthorized: false,
            },
            saver: {
                pathBodyDir: basePath,
                pathHeaders: path.join(basePath, 'headers.json'),
            },
            responseRender (data, resp, ctx) {
                logger.info(ctx.req.getUrl(), data.length)
                return data
            },
        },
        {
            location: /^\/?(documentation)/,
            origin: "https://docs.sw.siemens.com",
            pathname: '$1',
            requestOptions: {
                rejectUnauthorized: false,
            },
            saver: {
                pathBodyDir: basePath,
                pathHeaders: path.join(basePath, 'headers.json'),
            },
            responseRender (data, resp, ctx) {
                logger.info(ctx.req.getUrl(), data.length)
                return data
            },
        },
    ],
    dest: basePath,
})